golang有許多好用的資料結構,已經內建了,比起他的前輩C,方便許多.
今天介紹Map,簡單的宣告,賦值,與取出資料.
// hello34
package main
import (
	"fmt"
)
func main() {
	// map 宣告方式
	var mapLit map[string]int
	//  ^^^^^^ ^^^ ^^^^^^ ^^^
	//  名稱       key型態 資料型態
	// 賦值的方式
	mapLit = map[string]int{"長江一號": 999, "保龍二號": 543}
	// 列印內容出來
	fmt.Printf("%d\n", mapLit["長江一號"])
	fmt.Printf("%d\n", mapLit["保龍二號"])
}
執行結果:
λ ./hello34 
999
543